package tjs.study.notes.eureka.clienta.user.service.restTemplate;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Nicky.Tang on 2021/10/31 4:52 下午
 *
 * @since 02.12.10
 */
@Transactional
@Service
public class OrederRestTemplateService {
    private static final Logger logger = LoggerFactory.getLogger(OrederRestTemplateService.class);
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    JdbcTemplate jdbcTemplate;

    @LcnTransaction
    public void newOrder(String userId, StringBuilder stepBui) {
        jdbcTemplate.execute("UPDATE user_test ut SET ut.balance = ut.balance + 1 WHERE ut.id = 1;");
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://ms-consumer-order/order/newOrder/" + userId, String.class);
//        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://127.0.0.1:8011/order/newOrder/" + userId, String.class);
        String response = responseEntity.getBody();
        stepBui.append(response).append("\n");
        logger.warn(response);
    }
}
